﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.ServiceProcess;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using DbDao;

namespace SPerfMonitor
{
    public partial class Service1 : ServiceBase
    {
        private Timer t;
        private I_MediaDAO Model;

        public Service1()
        {
            InitializeComponent();
            this.Model = new MediaDao();
        }

        protected override void OnStart(string[] args)
        {
            t = new Timer(10000); // Timer de 10 secondes.
            t.Elapsed += new ElapsedEventHandler(t_Elapsed);
            t.Start();
        }

        protected override void OnStop()
        {
            t.Stop();
        }

        protected void t_Elapsed(object sender, EventArgs e)
        {
            
            I_PerfDetails detail = new PerfMonitor().getPerfDetails();

            this.Model.savePerfData(detail.CpuUsage, detail.RamUsage, detail.DDUsage,detail.startAllowed);


        }
    }
}